				<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register</title>
<style type="text/css">
#apDiv1 {
	position:absolute;
	width:602px;
	height:528px;
	z-index:1;
	left: 308px;
	top: 174px;
}
#apDiv2 {
	position:absolute;
	width:302px;
	height:279px;
	z-index:2;
	left: 928px;
	top: 176px;
}

#DivHR {
	position:absolute;
	width:981px;
	height:28px;
	z-index:2;
	left: 247px;
	top: 118px;
}
</style>
</head>

<body>
<pre><p>                           <a href="index.php" ><img src="../Resources/eMart logo.png" width="170" height="67" alt="Logo" /></a>                                                               <b><a  style="color:#000; text-decoration:none;" href="customer_support.php">Customer Support</a>  |  <a style="color:#000; text-decoration:none;" href="Terms.php">Privacy Policy</a></b>
<div id="DivHR"><hr/></div>

<div id="apDiv1" style="background-image:url(../Resources/Register%20Pannel.png); background-repeat:no-repeat">
<h4>                           REGISTERING NEW ACCOUNT </h4>
<form action="Register.php" method="post">
	<table>
    	<tr>
        	<td>First Name:</td>
            <td><input type="Text" name="firstname" style="width:200px" value= "<?php echo @$firstname; ?>" /></td>
         </tr>
         <tr>
        	<td>Last Name:</td>
            <td><input type="Text" name="lastname" style="width:200px" value="<?php echo @$lastname; ?>" /></td>
         </tr>
         <tr>
        	<td>Date of Birth:</td>
            <td><select name="dob_day" >
            	<option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15">15</option>
                <option value="16">16</option>
                <option value="17">17</option>
                <option value="18">18</option>
                <option value="19">19</option>
                <option value="20">20</option>
                <option value="21">21</option>
                <option value="22">22</option>
                <option value="23">23</option>
                <option value="24">24</option>
                <option value="25">25</option>
                <option value="26">26</option>
                <option value="27">27</option>
                <option value="28">28</option>
                <option value="29">29</option>
                <option value="30">30</option>
                <option value="31">31</option></select><select name="dob_month" >
                                                        <option value="1">January</option>
                                                        <option value="2">February</option>
                                                        <option value="3">March</option>
                                                        <option value="4">April</option>
                                                        <option value="5">May</option>
                                                        <option value="6">June</option>
                                                        <option value="7">July</option>
                                                        <option value="8">August</option>
                                                        <option value="9">September</option>
                                                        <option value="10">October</option>
                                                        <option value="11">November</option>
                                                        <option value="12">December</option></select> <select name="dob_year" >
                                                        									<option value ="1980">1970</option>
                                                                                            <option value ="1981">1971</option>
                                                                                            <option value ="1982">1972</option>
                                                                                            <option value ="1983">1973</option>
                                                                                            <option value ="1984">1974</option>
                                                                                            <option value ="1985">1975</option>
                                                                                            <option value ="1986">1976</option>
                                                                                            <option value ="1987">1977</option>
                                                                                            <option value ="1988">1978</option>
                                                                                            <option value ="1989">1979</option>
                                                                                            <option value ="1980">1980</option>
                                                                                            <option value ="1981">1981</option>
                                                                                            <option value ="1982">1982</option>
                                                                                            <option value ="1983">1983</option>
                                                                                            <option value ="1984">1984</option>
                                                                                            <option value ="1985">1985</option>
                                                                                            <option value ="1986">1986</option>
                                                                                            <option value ="1987">1987</option>
                                                                                            <option value ="1988">1988</option>
                                                                                            <option value ="1989">1989</option>
                                                                                            <option value ="1990">1990</option>
                                                                                            <option value ="1991">1991</option>
                                                                                            <option value ="1992">1992</option>
                                                                                            <option value ="1993">1993</option>
                                                                                            <option value ="1994">1994</option>
                                                                                            <option value ="1995">1995</option>
                                                                                            <option value ="1996">1996</option>
                                                                                            <option value ="1997">1997</option>
                                                                                            <option value ="1998">1998</option>
                                                                                            <option value ="1999">1999</option>
                                                                                            <option value ="2000">2000</option>
                                                                                            </select>
            </td>
         </tr>
         
         <tr>
         	<td>Email:</td>
            <td><input type="text" name="email" style="width:200px" value="<?php echo @$email; ?>" /></td>
         </tr>
         <tr>
         	<td>Address 1:</td>
            <td><input type="text" name="Address1" style="width:200px"  value="<?php echo @$Address1;?>"/></td>
    	</tr>
        <tr>
         	<td>Address 2:</td>
            <td><input type="text" style="width:200px" name="Address2" value="<?php echo @$Address2;?>"/></td>
    	</tr>
        <tr>
         	<td>Credit card number:</td>
            <td><input type="text" style="width:200px" name="ccard" /></td>
    	</tr>
        <tr>
         	<td>Card Type</td>
            <td><select name="card_type" >
            	<option value="NULL">Select card type</option>
                <option value ="visa">Visa</option>
                <option value ="discover">Discover</option>
                <option value ="mastercard">Mastercard</option>
                </select><img src="../Resources/ccards.png" width="78" height="18" alt="ccard" /></td>
    	</tr>
         <tr>
         	<td>Password:</td>
            <td><input type="password" style="width:200px" name="pin" /></td>
    	</tr>
        <tr>
         	<td>Repeat Password:</td>
            <td><input type="password" style="width:200px" name="pin2" /></td>
    	</tr>
    </table>
 	<input type="submit" value="Register" name="submit1" /><a href="Index.php"><input type="button" value ="Cancel" /></a>
</form>

</div>
<div id="apDiv2" style="background-image:url(../Resources/Sign%20in%20Pannel.png); background-repeat:no-repeat">
<h3>        Already Registered?</h3>
<form action="Register.php" method="post">
    <table>
            <tr>
                <td><p>Email Address: </p></td>
                <td><input type="text" name = "email" />
                </td>
            </tr>
            <tr>
                <td>Password:
                </td>
                <td><input type="password" name="passcode" />
                </td>
            </tr>
        </table>
        <input type="submit"  name = "submit2" value="Sign In" />
</form>

<?php
session_start();

if (isset($_POST['submit1']))
{
	if(!$_POST['firstname']|| !$_POST['lastname'] ||!$_POST['dob_day'] || !$_POST['dob_month'] ||!$_POST['dob_year'] ||!$_POST['email'] ||!$_POST['Address1'] || !$_POST['Address2'] ||! $_POST['pin'] ||! $_POST['pin2'] || !$_POST['ccard'] ||!$_POST['card_type'])
	//not reading the ccard, card type or pins. WHY?????
	{
		die("<strong>One or more critical fields left blank</strong>");
	}
	else
	{
		if($_POST['pin']!= $_POST['pin2'])
		{
			die("Passwords do not match");
		}
		else
		{
			if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["firstname"]) === 0 | preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["lastname"]) === 0)
			{
				die("Name can only be letters dashes or spaces and cannot start with a dash");
			}
			else
			{
				
				
					if(preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $_POST["pin"])=== 0)
					{
						die("Password not strong enough");
					}
					else
					{
						if(preg_match("/^[\d]{16}+$/",$_POST['ccard'])===0)
						{
							die("Credit Card Number can only contain numbers");

						}
						else
						{
							if(preg_match("/^[a-zA-Z]\w+(\.\w+)*\@\w+(\.[0-9a-zA-Z]+)*\.[a-zA-Z]{2,4}$/", $_POST["email"]) === 0)
							{
								die("email address not valid");
							}
							else
							{
								$con = mysql_connect("localhost","root","") or die ("Could not connect to DB!");
								mysql_select_db ("web project",$con) or die ("could not select DB!");
								
								$query = "SELECT * FROM members where `email` = '".$_POST['email']."'";
								$result = mysql_query($query);
								$num_results = mysql_num_rows($result);		 
								if($num_results > 0)
								{
									die("An account Already Exists for this email");										
								}
								else	
								{
																
									
									$firstname =$_POST['firstname'];
									$lastname = $_POST['lastname'];
									$mem_ID= $firstname[0]. $lastname[0]. rand(1000,9999);
									$day = $_POST['dob_day'];
									$month=$_POST['dob_month'];
									$year=$_POST['dob_year'];
									$dob=  $year."-" .$month."-".$day;
									
									$query2 = mysql_query("insert into members (`Mem_ID`, `membership_type`, `First_Name`, `Last_Name`, `Password`, `DOB`, `Address1`, `Address2`, `email`) values ('". $mem_ID."', 'Customer', '".$firstname."','".$lastname."', '".$_POST['pin']."','".$dob."', '".$_POST['Address1']."','".$_POST['Address2']."', '".$_POST['email']."')");
									
									$query3 = mysql_query("insert into `credit_info` (`Member_Id`, `creditcard`, `password` , `address`) values ('".$mem_ID."', '".$_POST['ccard']."', '".$_POST['pin']."',   '".$_POST['Address1']."')");                    
										
										mysql_close($con); 
										
										echo "<meta http-equiv='refresh' content='0;url=index.php'>"; 
										die("wait");
        
								}
								
							}
						}
					}
				
			}
		}
	}
	mysql_close($con); 
}


if (isset($_POST['submit2']))
{
$passcode = $_POST['passcode'];
	$email = $_POST['email'];
	
	$connect = mysql_connect("localhost","root","") or die ("Could not connect to DB!");
	mysql_select_db ("web project",$connect) or die ("could not select db!");
	
	$query = mysql_query("SELECT * FROM members ");
	$found = FALSE;
	
	while ($row = mysql_fetch_array($query))
	{	
		
		
		if (($row['email'] == $email) && ($row['Password'] == $passcode))
		{			
			$found = TRUE;
			$_SESSION['passcode'] = $passcode;
			
			break;
		}
		
	}
	if ($found == TRUE)
	{
		
		$_SESSION['fname'] = $row['First_Name'];
		$_SESSION['lname'] = $row['Last_Name'];
		$_SESSION['id'] = $row['Mem_ID'];
		$_SESSION['status'] = "IN";
		echo "<meta http-equiv='refresh' content='0;url=index.php'>";
			
		
	}
	
	if ($found == FALSE)
	{
		echo '<script language="javascript">alert("The Email Address and Password entered do not match! Please Try again . . .")</script>;'; 
	}
}

?>
</div>
<p>
</body>
</html>